home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue57 / System / ShadowForm.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-03-21  |  2.5 KB  |  91 lines

  1. unit ShadowForm;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   StdCtrls, ComCtrls, ExtCtrls;
  8.  
  9. type
  10.   TForm1 = class(TForm)
  11.     Panel1: TPanel;
  12.     Image1: TImage;
  13.     procedure FormClick(Sender: TObject);
  14.     procedure FormCreate(Sender: TObject);
  15.     procedure FormResize(Sender: TObject);
  16.   private
  17.     { Private declarations }
  18.     ShadowWidth: Integer;
  19.     RightShadow: TForm;
  20.     BotShadow: TForm;
  21.     procedure WMWindowPosChanged (var Message: TWMWindowPosChanged); message wm_WindowPosChanged;
  22.   public
  23.     { Public declarations }
  24.   end;
  25.  
  26. var
  27.   Form1: TForm1;
  28.  
  29. implementation
  30.  
  31. {$R *.DFM}
  32.  
  33. const
  34.     // LWA constants for SetLayeredWindowAttributes
  35.     lwa_ColorKey        = 1;
  36.     lwa_Alpha           = 2;
  37.  
  38.     // New extended window style for layering
  39.     ws_Ex_Layered       = $80000;
  40.  
  41. function SetLayeredWindowAttributes (Wnd: hWnd; crKey: ColorRef; bAlpha: Byte; dwFlags: DWord): Bool; stdcall;
  42. external 'user32.dll';
  43.  
  44. procedure TForm1.FormClick(Sender: TObject);
  45. begin
  46.     Close;
  47. end;
  48.  
  49. procedure TForm1.FormCreate(Sender: TObject);
  50. begin
  51.     ShadowWidth := 7;
  52.     RightShadow := TForm.Create (Self);
  53.     RightShadow.Parent := Application.MainForm;
  54.     RightShadow.BorderStyle := bsNone;
  55.     RightShadow.Width := ShadowWidth;
  56.     RightShadow.Color := clBlack;
  57.     RightShadow.Visible := True;
  58.     SetWindowLong (RightShadow.Handle, gwl_ExStyle, GetWindowLong (RightShadow.Handle, gwl_ExStyle) or ws_Ex_Layered);
  59.     SetLayeredWindowAttributes (RightShadow.Handle, 0, 150, lwa_Alpha);
  60.  
  61.     BotShadow := TForm.Create (Self);
  62.     BotShadow.Parent := Application.MainForm;
  63.     BotShadow.BorderStyle := bsNone;
  64.     BotShadow.Height := ShadowWidth;
  65.     BotShadow.Color := clBlack;
  66.     BotShadow.Visible := True;
  67.     SetWindowLong (BotShadow.Handle, gwl_ExStyle, GetWindowLong (BotShadow.Handle, gwl_ExStyle) or ws_Ex_Layered);
  68.     SetLayeredWindowAttributes (BotShadow.Handle, 0, 150, lwa_Alpha);
  69.  
  70.     FormResize (Sender);
  71. end;
  72.  
  73. procedure TForm1.WMWindowPosChanged (var Message: TWMWindowPosChanged);
  74. begin
  75.    Inherited;
  76.    if Assigned (RightShadow) and RightShadow.Visible then FormResize(Nil);
  77. end;
  78.  
  79. procedure TForm1.FormResize(Sender: TObject);
  80. begin
  81.     RightShadow.Height := Height;
  82.     RightShadow.Left := Left + Width;
  83.     RightShadow.Top := Top + ShadowWidth;
  84.  
  85.     BotShadow.Width := Width - ShadowWidth;
  86.     BotShadow.Left := Left + ShadowWidth;
  87.     BotShadow.Top := Top + Height;
  88. end;
  89.  
  90. end.
  91.